<!-- 合同列表 - 综合表单页面 -->
<template>
  <div class="page-container">
    <ex_super_table_page v-bind="option" ref="SuperTablePage">

    </ex_super_table_page>
    <ex_super_dialog_form ref="formDialog" :title="dialogTitle" v-bind="dialog"
      @afterSubmitSuccess="$refs['SuperTablePage'].reload()" />
  </div>
</template>
<script>
let moduleName = "label_srm_contract_management_list";
import moment from "moment-mini-ts";
export default {
  title: moduleName,
  components: {},
  data() {
    return {
      option: {
        //搜索框内容
        search: {
          //搜索框内容，key为搜索字段，label为标签提示
          model: [
            {
              label: "label_srm_contract_management_contract_name",
              key: "contractName",
            },
            {
              label: "label_srm_contract_management_status",
              key: "status", type: 'select', enum: 'ContractManagementStatusEnum',
            },
            {
              label: "label_srm_contract_management_sign_start_date",
              key: "signatureTimeStart", type: 'date-picker',
            },
            {
              label: "label_srm_contract_management_sign_end_date",
              key: "signatureTimeEnd", type: 'date-picker',
            },
            {
              label: "label_srm_contract_management_sign_supplier",
              key: "contractedSupplier",
            },

          ],
        },
        action: [
          {
            label: "label_new" + moduleName,
            attrs: { icon: "el-icon-plus" },
            click: () => {
              this.dialogTitle = "新增" + moduleName;
              this["$refs"]["formDialog"].show(null, {setData:true});
            },
          },
        ],

        table: {
          url: "/srm-api/supplier/ContractManagementRpc/selectPage.json",
          attrs: {},
          model: [
            { key: "contractCode", label: "label_srm_contract_management_contract_no", 'min-width': '200', },
            { key: "contractName", label: "label_srm_contract_management_contract_name", 'min-width': '200', },
            { key: "supplierName", label: "label_srm_contract_management_sign_supplier", 'min-width': '150', },
            { key: "status", label: "label_srm_contract_management_status", width: '130', formatter: (r, c, v, i) => this.$enumShow(v, "ContractManagementStatusEnum") },
            { key: "contractType", label: "label_srm_contract_management_contract_type", width: '130', formatter: (r, c, v, i) => this.$enumShow(v, "ContractTemplateTypeEnum") },
            {
              key: "signatureTime",
              label: "label_srm_contract_management_sign_date", width: '150',
              formatter: (r, c, v, i) => this.$dateFormat(v),
            },
            {
              key: "validTimeStart",
              label: "label_srm_contract_management_validity_date", width: '170',
              formatter: (r, c, v, i) =>
                this.$dateFormatDate(v,) +
                "-" +
                this.$dateFormatDate(r.validTimeEnd,),
            },
            {
              key: "validTimeStart",
              label: "label_srm_contract_management_days_expiration", width: '130',
              formatter: (r, c, v, i) =>
                moment.duration(r.validTimeEnd - new Date().getTime()).asDays().toFixed(0) + '天',
            },
            // { key: "notes", label: "备注" },
          ],
          operate: [
            {
              label: 'label_srm_contract_management_contract_down',
              disabled: (row) => !row.contractAccessory,
              click: (row) => {
                window.open(this.$ex_default_download_url + row.contractAccessory, '_blank')
              }
            },
            {
              label: "label_edit",
              click: (row) => {
                this.dialogTitle = "编辑" + moduleName;
                this["$refs"]["formDialog"].show({ id: row["id"] }, false);
              },
            },
            {
              label: "label_delete",
              type: "confirm-button",
              url: "/srm-api/supplier/ContractManagementRpc/remove.json",
              message: "label_fms_bank_card_confirm_delete", buttonClass: "button_text_danger", confirmButtonType: 'danger',
              params: (row) => {
                return { id: row["id"] };
              },
              done: ["reload", "tip"],
            },
          ],
        },
      },

      dialogTitle: "",
      dialogFile: null,
      dialogSignatureTime: null,
      dialogValidTime: null,
      dialog: {
        submitUrl: "/srm-api/supplier/ContractManagementRpc/saveUpdate.json",
        detailUrl: "/srm-api/supplier/ContractManagementRpc/detail.json",
        detailDataHandle: (data) => {
          data.validTime = [data.validTimeStart, data.validTimeEnd]
          if (data.contractAccessory) data.contractAccessoryFile = [{
            filePath: data.contractAccessory,
            fileName: "合同文件.link",
          }]
          return data
        },
        submitDataHandle: (data) => {
          if (this.dialogFile) {
            data.contractAccessory = this.dialogFile.filePath
          } else {
            data.contractAccessory = null
          }
          return data
        },
        form: {
          //弹窗表单设置，设置方式与搜索框对象一致。
          model: [
            { header: "label_srm_contract_management_basic_info" },

            { key: "contractName", label: "label_srm_contract_management_contract_name", maxlength: '50', 'show-word-limit': true },
            {
              key: "contractTemplaterId", label: "label_srm_contract_management_contract_temp", type: 'select', storeData: true, option: { label: 'scontractTemplateName', value: 'contractTemplaterId' },
              url: '/srm-api/supplier/ContractTemplateRpc/getContractTemplateDict.json',
              keyExtra: { scontractTemplateName: 'scontractTemplateName', contractTemplateCode: 'contractTemplateCode' },
            },
            {
              key: "supplierId", label: "label_srm_contract_management_sign_supplier", type: 'select', storeData: true, option: { label: 'supplierName', value: 'supplierId' },
              url: '/srm-api/supplier/SupplierRpc/getSupplierDict.json',
              listHandler: e => e.map(it => {
                    it.disabled = it.status === 'DISABLED'
                    return it
                  }),
              keyExtra: { supplierName: 'supplierName', supplierCode: 'supplierCode', supplierType: 'supplierType' },
            },
            // { key: "supplierType", label: "供应商类型" },

            { key: "contractCode", label: "label_srm_contract_management_contract_no", maxlength: '50', 'show-word-limit': true },
            { key: "status", label: "label_srm_contract_management_status", type: 'select', enum: 'ContractManagementStatusEnum' },
            { key: "contractType", label: "label_srm_contract_management_contract_type", type: 'select', enum: 'ContractTemplateTypeEnum' },
            {
              key: "signatureTime", label: "label_srm_contract_management_sign_date", type: "date-picker",
              on: {
                change: e => this.dialogSignatureTime = e,
              },
            },
            {
              key: "validTime",
              label: "label_srm_contract_management_validity_time",
              type: "date-picker",
              keyExtra: { 0: 'validTimeStart', 1: 'validTimeEnd' },
              on: {
                change: e => this.dialogValidTime = e,
              },
              attrs: {
                type: 'daterange',
                'range-separator': "至",
                'start-placeholder': "开始日期",
                'end-placeholder': "结束日期",
              }
            },
            // { key: "validTimeEnd", label: "结束生效时间", type: "date-picker" },
            { key: "notes", label: "label_remark", maxlength: '50', 'show-word-limit': true, attrs: { type: 'textarea' } },
            {
              key: 'contractAccessoryFile', label: 'label_srm_contract_management_contract_file', type: 'upload-file',
              limitUploadHide: true, accept: '.doc,.docx,.pdf', maxSize: 10,
              on: { input: (filelist) => this.dialogFile = _.head(filelist) },
            },
          ],
          rules: {
            contractCode: { required: true, message: "请输入合同编号", trigger: "change" },
            contractName: [
              { required: true, message: "请输入合同名称", trigger: "change" },
            ],
            contractedSupplier: [
              { required: true, message: "请输入签约供应商", trigger: "change" },
            ],
            supplierId: [
              { required: true, message: "请选择供应商", trigger: "change" },
            ],
            status: [
              { required: true, message: "请输入合同状态", trigger: "change" },
            ],
            contractType: { required: true, message: "请输入合同类型", trigger: "change" },
            signatureTime: { required: true, message: "请输入签订日期", trigger: "change" },
            validTime: { required: true, message: "请输入有效期", trigger: "change" },

            contractAccessoryFile: { required: true, message: "请上传合同文件", trigger: "change" },
          },
        },
      },
    };
  },
  created() {
  },
  methods: {},
};
</script>
<style>

</style>
